<template>
  <el-dialog :visible.sync="dialog" title="订课审批">
    <el-form ref="auditForm" :model="auditForm" :rules="auditRules" label-width="100px">
      <el-form-item label="订购课程:" prop="courseName">
        {{ courseName }}
      </el-form-item>
      <el-row>
        <el-col :span="8">
          <el-form-item label="订购课时:">
            {{ bookHour }} 课时
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="赠送课时:">
            {{ largessHour }} 课时
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="订课备注:">
            {{ remark }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="审核结果:" prop="auditStatus">
        <el-radio-group v-model="auditForm.auditStatus">
          <el-radio :label="10">通过</el-radio>
          <el-radio :label="11">拒绝</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="审核备注:">
        <el-input v-model="auditForm.auditRemark" :rows="4" type="textarea" placeholder="输入审核备注" />
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="submitLoading" type="primary" @click="auditSubmit">提交</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { bookCourseAudit } from '@/api/course'

export default {
  props: {
    orderCourseAuditId: {
      type: Number,
      required: true
    },
    courseName: {
      type: String,
      default: ''
    },
    bookHour: {
      type: Number,
      required: true
    },
    largessHour: {
      type: Number,
      required: true
    },
    remark: {
      type: String,
      required: false
    }
  },
  data() {
    return {
      dialog: false,
      submitLoading: false,
      auditForm: {
        orderCourseAuditId: 0,
        auditStatus: 10,
        auditRemark: ''
      },
      auditRules: {
        auditStatus: [{ required: true, message: '请选择审核状态', trigger: 'blur' }]
      }
    }
  },
  methods: {
    auditSubmit() {
      this.$refs.auditForm.validate((valid) => {
        if (valid) {
          this.submitLoading = true
          this.auditForm.orderCourseAuditId = this.orderCourseAuditId
          bookCourseAudit(this.auditForm).then(res => {
            this.$message({
              message: '审核成功',
              type: 'success'
            })
            this.submitLoading = false
            this.dialog = false
            this.$parent.init()
          }).finally(() => {
            this.submitLoading = false
          })
        }
      })
    },
    cancel() {
      this.dialog = false
    }
  }
}
</script>

<style>

</style>